package com.feihao.zhou.demo02Test.controller;

import com.feihao.zhou.demo02Test.domain.Student;
import com.feihao.zhou.demo02Test.service.StudentService;
import com.feihao.zhou.demo02Test.service.StudentServiceImpl;
import org.junit.Test;

import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class StudentController {
    private StudentService studentService = new StudentServiceImpl();
    //需要调用service的方法：

    //查询所有学生：
    @Test
    public void findAll() {
        List<Student> list = studentService.findAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }


    //根据学生学号查询：
    @Test
    public void findByID() {
        Student stu = studentService.findByID(1);
        if (stu == null) {
            System.out.println("没有此号学号学生！");
        } else {
            System.out.println(stu);
        }
    }


    //新增学生：
    @Test
    public void insert() {
        Student student = new Student(8, "田七", 25, new Date());
        int insert = studentService.insert(student);
        if (insert == 0) {
            System.out.println("添加失败");
        } else {
            System.out.println("添加成功");
        }
    }

    //删除学生：
    @Test
    public void delete() {
        System.out.println("输入要删除的学生sid:");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int delete = studentService.delete(i);
        if (delete == 0) {
            System.out.println("删除失败");
        } else {
            System.out.println("删除成功");
        }
    }


    //修改学生：
    @Test
    public void update() {
        System.out.println("输入修改的学生sid:");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int update = studentService.update(i);
        if (update == 0) {
            System.out.println("修改失败");
        } else {
            System.out.println("修改成功");
        }

    }
}
